package cn.itcast.com.homework.day720;

import java.util.Scanner;

/*
1. 创建两个类，分别用来表示长方形和正方形，同时定义所需的成员变量，
   代表长方形或者正方形的边长，在两个类中分别定义两个方法，用来求对应形状的面积和周长，
   Area and perimeter
   并定义相应的get，set方法，获取和改变方形和正方形的变长。
 */
public class test1 {
    public static void main(String[] args) {
        rectangle rec = new rectangle();
        System.out.println("当前长方形长度为：" + rec.getLength());
        System.out.println("当前长方形宽度为：" + rec.getWidth());
        rec.Area();
        rec.Perimeter();
        System.out.println("输入值改变长宽");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入长度");
        rec.setLength(scanner.nextInt());
        System.out.println("请输入宽度");
        rec.setWidth(scanner.nextInt());
        System.out.println("修改后长方形长度为：" + rec.getLength());
        System.out.println("修改后长方形宽度为：" + rec.getWidth());

        System.out.println("*************************************");

        square square = new square();
        System.out.println("当前长方形长度为：" + square.getLength());
        square.Area();
        square.Perimeter();
        System.out.println("输入值改变长宽");
        System.out.println("请输入长度");
        square.setLength(scanner.nextInt());
        System.out.println("修改后正方形长度为：" + square.getLength());
    }
}
class rectangle{
    int length;
    int width;

    public rectangle() {
        this.length = 100;
        this.width = 50;
    }

    public int getLength() {
        return length;
    }

    public int getWidth() {
        return width;
    }

    public void setLength(int length) {
        this.length = length;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public void Area(){
        int area = this.getLength() * this.getWidth();
        System.out.println("面积等于：" + area);
    }

    public void Perimeter(){
        int preimeter = (this.getLength() + this.getWidth()) * 2;
        System.out.println("周长等于：" + preimeter);
    }

}
class square{
    int length;

    public square() {
        this.length = 5;
    }

    public int getLength() {
        return length;
    }

    public void setLength(int length) {
        this.length = length;
    }

    public void Area(){
        int area = this.getLength() * this.getLength();
        System.out.println("面积等于：" + area);
    }

    public void Perimeter(){
        int preimeter = getLength()*4;
        System.out.println("周长等于：" + preimeter);
    }
}